import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class NormalTextfield extends StatelessWidget {
  final String? hintText;
  final EdgeInsets? margin;
  final bool obscureText;
  final int? maxLength;
  final TextInputType? keyboardType;
  final FocusNode? focusNode;
  final List<TextInputFormatter>? inputFormatters;
  final TextEditingController? controller;
  final Color backgroundColor;
  final double borderRadius;

  /// 输入框左边距
  final double paddingLeft;
  final TextAlign? textAlign;
  final Function()? onTap;
  final Function(String val)? onSubmited;
  final Function(String val)? onChanged;

  const NormalTextfield(
      {Key? key,
      this.hintText,
      this.onTap,
      this.margin,
      this.obscureText = false,
      this.maxLength,
      this.focusNode,
      this.textAlign,
      this.keyboardType,
      this.inputFormatters,
      this.controller,
      this.onSubmited,
      this.onChanged,
      this.borderRadius = 3,
      this.paddingLeft = 0,
      this.backgroundColor = Colors.white})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 53,
      margin: margin ?? EdgeInsets.zero,
      decoration: BoxDecoration(color: backgroundColor, borderRadius: BorderRadius.circular(borderRadius)),
      child: TextField(
        obscureText: obscureText,
        maxLength: maxLength,
        keyboardType: keyboardType,
        focusNode: focusNode,
        textAlign: textAlign ?? TextAlign.left,
        controller: controller,
        onTap: onTap,
        inputFormatters: inputFormatters,
        decoration: InputDecoration(
            border: InputBorder.none,
            hintText: hintText,
            prefix: SizedBox(
              width: paddingLeft,
            ),
            counterText: "",
            suffix: SizedBox(
              width: 15,
            )),
        onSubmitted: onSubmited,
        onChanged: onChanged,
      ),
    );
  }
}
